package com.yanqu.road.server.logic.season;

import com.yanqu.road.entity.enums.eSeasonRewardType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.logic.season.washe.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class BaseSeasonFactory {

    public static final Logger logger = LogManager.getLogger(BaseSeasonReward.class.getName());

    private static final Map<eSeasonRewardType, Class<? extends BaseSeasonReward>> classMap = new ConcurrentHashMap<>();

    static {
        classMap.put(eSeasonRewardType.WasheGetScoreZhanLing, WasheGetScoreZhanLingCondition.class);
        classMap.put(eSeasonRewardType.WasheScoreRank, WasheScoreRankCondition.class);
        classMap.put(eSeasonRewardType.JinBiaoScoreRank, WasheJinBiaoScoreRankCondition.class);
        classMap.put(eSeasonRewardType.JinBiaoPeakRank, WasheJinBiaoPeakRankCondition.class);
        classMap.put(eSeasonRewardType.WasheTimeLimitTask, WasheTimeLimitTaskCondition.class);
        classMap.put(eSeasonRewardType.WasheNewHandScoreArch, WasheNewHandScoreArchCondition.class);
        classMap.put(eSeasonRewardType.WasheScoreArch, WasheScoreArchCondition.class);
    }

    public static BaseSeasonReward getInstance(eSeasonRewardType type, GamePlayer player) {
        // 拿类
        Class<? extends BaseSeasonReward> aClass = classMap.get(type);
        if (aClass == null) {
            logger.error("can not find SeasonReward type {}, see BaseSeasonReward.getInstance", type.getIntValue());
            return null;
        }

        // 生成实例 并初始化
        try {
            BaseSeasonReward instance = aClass.getConstructor(eSeasonRewardType.class, GamePlayer.class).newInstance(type, player);
            instance.init();
            return instance;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
